<style>
	.amap-wrapper {
		width: 900px;
		height: 600px;
	}
	
	.amap-demo {
		height: 100px;
	}
</style>
<template>
	<div>
		<Modal v-model="modalShow" :closable='false' :mask-closable=false fullscreen>
			<p slot="header">添加优惠券</p>
			<Row>
				<Col span="16">
				<Form ref="formData" :model="formData" label-position="left" :label-width="100">
					<FormItem label="优惠券类型" prop="type">
						<Select v-model="formData.type" filterable>
							<Option value="1">代金券</Option>
						</Select>
					</FormItem>
					<FormItem label="归属网点" prop="dot_id">
						<Select v-model="formData.dot_id" filterable>
							<Option v-for="(item,key) in getSearchData.dot" :value="key" :key="key">{{ item }}</Option>
						</Select>
					</FormItem>
					

					<FormItem label="优惠券面值" prop="price">
						<Input v-model="formData.price" />
					</FormItem>

					<FormItem label="有效期" prop="end_day">
						<Input v-model="formData.end_day" />
					</FormItem>
					

					<FormItem label="使用规则" prop="rule_price">
						<Input v-model="formData.rule_price" />
					</FormItem>

					<FormItem label="发放限制数量" prop="limit_num">
						<Input v-model="formData.limit_num" />
					</FormItem>

				</Form>
				</Col>
			</Row>

			<div slot="footer">
				<Button type="text" @click="cancel">取消</Button>
				<Button type="primary" @click="add" :loading='saveLoading'>保存 </Button>
			</div>
		</Modal>

	</div>
</template>
<script>
	import {
		addCoupon,
		getData
	} from '@/api/coupon'

	//import Editor from '_c/editor'
	//import Upload from '_c/common/upload'
	export default {
		components: {
			//  Editor,
			//  Upload
		},
		created() {
			let t = this;
			t.getSearchDataExcute();
		},
		data() {
			let t = this;
			return {
				modalShow: true,
				saveLoading: false,
				mapModal: false,
				mapModal1: false,
				getSearchData: {
					dot: [],
				},
				formData: {
					type: '',
					dot_id: '',
					price: '',
					end_day: '',
					rule_price: '',
					limit_num: '',
				}
			}
		},
		methods: {
			getSearchDataExcute() {
				let t = this;
				getData().then(res => {
					t.getSearchData.dot = res.data.data.dot;
				}, function(error) {})
			},
			add() {
				let t = this
				t.$refs.formData.validate((valid) => {
					if(valid) {
						t.saveLoading = true
						//console.log(JSON.stringify(t.formData));
						addCoupon(t.formData).then(res => {
							if(res.data.code == 1) {
								t.saveLoading = false
								t.modalShow = false
								t.$emit('on-add-modal-success')
								t.$emit('on-add-modal-hide')
								t.$Notice.success({
									title: res.data.msg
								})
							} else {
								t.saveLoading = false
								t.$Notice.error({
									title: res.data.msg
								})
							}

						}, function(error) {
							t.saveLoading = false
						})
					}
				})
			},
			cancel() {
				this.$emit('on-add-modal-hide')
				this.modalShow = false
			}
		},

	}
</script>